package com.iori.common.db.extend;

import java.util.ResourceBundle;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.iori.common.db.DBEnvConstant;
import com.iori.common.db.dbctrl.DBController;
import com.iori.common.db.dbctrl.SqlListCollection;
import com.iori.common.util.PropertiesUtil;

public class DBInitClass {
	private static ResourceBundle config = null;

	private static final String SYSTEM_PROPERTY_FILE_NAME = "dbenvconfig";

	private static final String SQLLIST_NAME = "sqllist.name";

	private static final String SQLLIST_CONFIG_FILE_NAME = "sqllist";

	private static Log logger = LogFactory.getLog(DBInitClass.class);

	private static DBInitClass instance = null;

	public static void init() {
		if (instance == null)
			instance = new DBInitClass();
	}

	private DBInitClass() {

		if (config == null) {
			try {
				config = ResourceBundle.getBundle(SYSTEM_PROPERTY_FILE_NAME);
			} catch (Exception e) {
				logger.error(e.getMessage());
				// throw new DBException(e);
			}
		}

		try {
			// データベースにアクセスするパラメータの設定
			DBController.init();
			// SQL文のパスの設定
			SqlListCollection.init();
			// SQLリストの設定
			SqlListCollection.put(DBEnvConstant.getConfig(SQLLIST_NAME),
					SQLLIST_CONFIG_FILE_NAME);
		} catch (Exception ex) {
			logger.error("Error! in SqlList initialize - " + ex.getMessage());
			// throw ex;
		}
	}
}
